package com.rockywong.springcloud.feign;

import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by rockywong on 2018/8/3.
 */
@FeignClient(value = "eureka-client", configuration = UploadClient.MultipartSupportConfig.class)
public interface UploadClient {

    @PostMapping(value = "upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    int upload(@RequestPart(value = "file")MultipartFile file);

    /**
     * 配置信息
     *
     * @Author Rocky Wong
     * @Date 2018/9/25 下午5:39
     *
     */
    @Configuration
    class MultipartSupportConfig {
        @Bean
        public feign.codec.Encoder feignFormEncoder() {
            return new SpringFormEncoder();
        }
    }
}
